package com.hzy.admin.services.system.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzy.admin.services.system.ISysAppLogService;
import com.hzy.admin.models.vo.system.TableVo;
import com.hzy.admin.repository.mapper.system.SysAppLogMapper;
import com.hzy.admin.repository.entity.system.SysAppLog;
import com.hzy.toolkit.Tools;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hzy
 * @since 2020-04-29
 */
@Service
public class SysAppLogServiceImpl extends ServiceImpl<SysAppLogMapper, SysAppLog> implements ISysAppLogService {

    /**
     * 查找列表
     *
     * @param page
     * @param size
     * @param search
     * @return
     */
    @Override
    public TableVo<Map<String, Object>> findList(Integer page, Integer size, SysAppLog search) {
        Page<Map<String, Object>> iPage = new Page<>(page, size);
        List<Map<String, Object>> data = this.baseMapper.getList(iPage, search);
        return TableVo.page(iPage, data);
    }

    /**
     * 根据 id 查询表单数据
     *
     * @param id
     * @return
     */
    @Override
    public Map<String, Object> findById(String id) {
        Map<String, Object> map = new HashMap<String, Object>();

        SysAppLog model = this.baseMapper.selectById(id);

        map.put("id", id);
        map.put("model", Tools.nullSafe(model, new SysAppLog()));
        return map;
    }

    /**
     * 保存数据
     *
     * @param model
     * @return
     */
    @Transactional
    @Override
    public String insertOrUpdate(SysAppLog model) {
        this.saveOrUpdate(model);
        return model.getId();
    }

    /**
     * 删除
     *
     * @param ids
     */
    @Transactional
    @Override
    public void deleteByIds(List<String> ids) {
        this.removeByIds(ids);

    }

}
